package flow;

import java.util.ArrayList;
import java.util.List;

/**
 * 找出所有的4位吸血鬼数字
 */
public class Vampire {

    static boolean test(int num, int a, int b) {
        if(num % 100 == 0)
            return false;
        List<Integer> arr = getBit(num);
        List<Integer> arr1 = getBit(a);
        if(!arr.containsAll(arr1))
            return false;
        List<Integer> arr2 = getBit(b);
        if(!arr.containsAll(arr2))
            return false;
        arr2.addAll(arr1);
        if(!arr2.containsAll(arr))
            return false;
        return true;
    }

    static List<Integer> getBit(int i) {
        List<Integer> list = new ArrayList<>();
        while(i > 0) {
            list.add(i % 10);
            i /= 10;
        }
        return list;
    }

    public static void main(String[] args) {
        for(int i = 10; i < 99; i ++) {
            for(int j = 10; j < 99; j ++) {
                int t = i * j;
                if(t < 1000)
                    continue;
                if(t > 9999)
                    break;
                if(test(t, i, j))
                    System.out.printf("%d = %d * %d\n", t, i, j);
            }
        }
    }
}
